<template>
  <div class="nav">
    <div class="banxin flex">
      <h1 class="logo">
        <a href="#">
          <img src="../../assets/images/indexLogo.png" alt="" />
        </a>
      </h1>
      <ul class="router-link flex">
        <!-- <li><span class="active">首页</span></li>
        <li><span>全部商品</span></li>
        <li><span>个人中心</span></li>
        <li><span>我的订单</span></li>
        <li><span>专属福利</span></li> -->
        <li v-for="item in links" :key="item.id"><span
          :class="{active: item.reg.test($route.path)}"
          @click="$router.push(item.path)"
        >{{item.text}}</span></li>
      </ul>
      <div class="search-bar flex">
        <input @keyup.enter="search" v-model="keyworld" type="text" placeholder="搜索商品"/>
        <span @click="search" class="btn"
          ><img src="../../assets/images/search.png" alt=""
        /></span>
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      keyworld:'',
      links:[
        {id:1,text:'首页',path:'/home', reg:/\/home/},
        {id:2,text:'全部商品',path:'/allgoods', reg:/\/allgoods/},
        {id:3,text:'个人中心',path:'/personal', reg:/\/personal/},
        {id:4,text:'我的订单',path:'/myorders', reg:/\/myorders/},
        {id:5,text:'专属福利',path:'/frees', reg:/\/frees/},
      ]
    };
  },
  methods:{
    search(){
      // 把输入框里面的文字，带到 全部商品页面，发请求，展示数据
      // 跳转到全部商品，带上keyworld
      this.$router.push(`/allgoods?keyworld=${this.keyworld}`)
      // this.$router.push({
      //   name : 'AllGoods',
      //   query : {
      //     keyworld:this.keyworld
      //   }
      // })

      // 把输入框清空
      this.keyworld = ''
    }
  }
};
</script>
 
<style lang = "less" scoped>
.nav {
  .banxin {
    padding: 14px 0;
    justify-content: space-between;
    ul {
      padding-top: 45px;
      li {
        padding: 0 20px;
        span {
          cursor: pointer;
          font-size: 16px;
          font-family: SourceHanSansSC;
          font-weight: 700;
          color: #333;
          line-height: 23px;
          &.active {
            color: #0A328E;;
          }
        }
      }
    }
    .search-bar {
        padding-top: 30px;
        height: 40px;
        input {
            box-sizing: border-box;
            height: 40px;
            width: 214px;
            border-radius: 20px 0 0 20px;
            border: 1px solid #ccc;
            border-right: 0;
            padding-left: 20px;
        }
        .btn {
            width: 50px;
            height: 40px;
            border-radius: 0 20px 20px 0;
            background: #0A328E;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
  }
}
</style>